const app = getApp();
const regeneratorRuntime = global.regeneratorRuntime = require("../libs/regenerator");
const co = require('../libs/co');
const passport = require("../services/passport/passport");

Page({
    data:{
       hidden:false,
       scrollHeight: 0,
       hasMore:true,
       isLoad:true,
       scrollTop:0
    },
    onLoad: function(options) {
        app.launchOptions = options;
        /* !Do not Remove the follow line, used for build tool.*/
        /*{ComponentLaunchJs}*/
        var that = this;
         wx.getSystemInfo({
             success: function(res) {
                 that.setData({
                     scrollHeight: res.windowHeight
                 });
             }
         });
    },
    onShow: function() {
      this.loadProducts();
    },
    loadProducts: function () {
      var that = this;
      co(function *() {
          let productService = require("../services/mall/productService");
          let products = yield productService.getFavorite();
          console.log(products);
          if (products && products.length) {
            that.setData({
                products: products,
                hidden: true,
                isLoad: true
            });
          } else {
            self.setData({
              hasMore:false,
              isLoad: true
            });
          }
      });
    },
    onReady:function(){

    },
    clickitem: function (e) {   //带着specId 去详情界面
        var specId = e.currentTarget.dataset.specid;
        wx.navigateTo({
            url: '/pages/page9?id=' + specId,
        })
    },
    /* !Do not Remove the follow line, used for build tool.*/
    /*{ComponentJs}*/

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    //页面滑动到底部
     bindDownLoad:function(){
       if (this.data.hasMore && this.data.isLoad) {
         this.setData({
           hidden:false,
           isLoad: false
         });
         this.loadProduct();
         console.log("height:" + this.data.scrollHeight);
       }
     },
     scroll:function(event){
       //该方法绑定了页面滚动时的事件，我这里记录了当前的position.y的值,为了请求数据之后把页面定位到这里来。
        this.setData({
            scrollTop : event.detail.scrollTop,
            hidden: false
        });
     },

});
